use core::arch::asm;

use crate::println;


pub fn console_putchar(c:usize){
    #[allow(deprecated)]
    sbi_rt::legacy::console_putchar(c);
}


const TIMER_FREQUENCY: u64 = 1_0000_000; 
pub fn sleep(seconds: u64){
    let current_time=riscv::register::time::read();
    let target_time = current_time as u64+ seconds * TIMER_FREQUENCY;
    sbi_rt::set_timer(target_time);
    unsafe {
      asm!("wfi")  
    }
}

pub fn shutdown(failure: bool) -> ! {
    use sbi_rt::{system_reset, NoReason, Shutdown, SystemFailure};
    if !failure {
        system_reset(Shutdown, NoReason);
    } else {
        system_reset(Shutdown, SystemFailure);
    }
    unreachable!()
}